<template>
	<view class="hotMovie-item" @tap="getDetail(item.id)" @longpress="showActionSheet(item)">
		<view class="left">
			<image @tap.stop="viewImage(item.img)" :src="item.img" mode="widthFix"></image>
		</view>
		<view class="center">
			<view class="m_title">{{item.nm}}</view>
			<view class="m_score" v-if="item.globalReleased==true">
				观众评：<text style="color: orange;font-weight: bold;font-size: 28upx;">{{item.sc}}</text>
			</view>
			<view class="m_with" v-if="item.globalReleased==false">
				<text style="color: orange;font-weight: bold;font-size: 28upx;">{{item.wish}}</text>想看
			</view>
			<view class="m_star">主演：{{item.star}}</view>
			<view class="m_showInfo" v-if="item.showInfo">{{item.showInfo}}</view>
			<view class="m_showInfo" v-if="!item.showInfo">{{item.rt}}上映</view>
		</view>
		<view class="right">
			<button @tap.stop="buyTicket(item.id)" class="btnBuy" v-if="item.globalReleased==true">购票</button>
			<button @tap.stop="buyTicket(item.id)" class="btnPre" v-if="item.globalReleased==false">预售</button>
		</view>
	</view>
</template>
<script>
	export default {
		name:"movieItem",
		props:["item","m_list"], 
		data(){
			return{
				
			}
		},
		created(){
			
		},
		methods:{ 
			viewImage(img){
				uni.previewImage({
					urls:this.m_list.map(item=>item.img),
					current:img
				});
				 
				
			},
			buyTicket(id){ 
				uni.navigateTo({
					url:`/pages/buyTicket/buyTicket?id=${id}`
				});
			},
			getDetail(id){
				uni.navigateTo({
					url:`/pages/mvoieDetail/movieDetail?id=${id}`
				});
			},
			/*长按弹出菜单*/
			showActionSheet(item){
				uni.showActionSheet({
					itemList:["添加收藏","查看详细"],
					success: (res) => {
						if(res.tapIndex==0){
							let  saveCollection=uni.getStorageSync("saveCollection")||[];
							let index=saveCollection.map(s_item=>s_item.id).indexOf(item.id)
							let isExists = index==-1?false:true;
							if(!isExists){
								//说明之前的不存在
								saveCollection.push({...item,s_time:new Date().toLocaleString()});
							}
							else{
								//说明已经存在了
								saveCollection[index]={...item,s_time:new Date().toLocaleString()};
							}
							uni.setStorageSync("saveCollection",saveCollection);
							uni.showToast({
								title:"收藏成功"
							});
							
						}
						else if(res.tapIndex==1){
							uni.navigateTo({
								url:`/pages/mvoieDetail/movieDetail?id=${item.id}`
							});
						}
					}
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	@mixin flexbox($dir:row){
		display: flex;
		flex-direction: $dir;
		width: 100%;
		@content;
	}
	$primaryColor:#e54847;
	.hotMovie-item{
		@include flexbox();
		box-shadow: 0px 2upx 2upx #EFEFF4;
		box-sizing: border-box;
		padding: 5upx;
		.left{
			width: 160upx;
			>image{
				width: 100%;
				display: block;
			}
		}
		.center{
			flex: 1;
			box-sizing: border-box;
			padding: 0px 5upx;
			@include flexbox(column){
				justify-content: space-between;
			}
			font-size: 24upx;
			.m_title{
				font-size: 30upx;
				font-weight: bold;
			}
		}
		.right{
			@include flexbox(column){
				justify-content: center;
				align-items: center;
				width: 140upx;
			}
			.btnBuy{
				width: 120upx;
				border: none;
				background-color: $primaryColor;
				color: white;
				font-size: 24upx;
			}
			.btnPre{
				@extend .btnBuy;
				background-color: #3c9fe6;
			}
		}
	}
	
</style>